package com.sgb.auction.activity;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.sgb.auction.R;
import com.sgb.auction.databinding.ActivityBiddingRecordBinding;
import com.sgb.auction.fragment.AllOfferFragment;
import com.sgb.auction.fragment.MyOfferFragment;
import com.sgb.auction.viewmodule.BiddingRecordModel;
import com.swgk.core.base.AppActivity;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;
import java.util.ArrayList;

/**
 * Time:2021/11/19
 * AUTHOR:F_Q
 * Description:竞买记录
 */
public class BiddingRecordActivity extends AppActivity {

    private BiddingRecordModel mModel;
    private ActivityBiddingRecordBinding mBinding;
    private String[] mTitles = {"全部出价", "我的出价"};
    private ArrayList<Fragment> mFragments;
    private SlidingFragmentPagerAdapter mPagerAdapter;

    public static void start(Context context, String title, String no) {
        Intent intent = new Intent();
        intent.putExtra("title",title);
        intent.putExtra("no",no);
        intent.setClass(context, BiddingRecordActivity.class);
        context.startActivity(intent);
    }
    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_bidding_record);
        mModel = new ViewModelProvider(this).get(BiddingRecordModel.class);
        mModel.setActivity(BiddingRecordActivity.this);
        mBinding.includeTitle.ivBack.setOnClickListener(v -> finish());
        mBinding.includeTitle.titleView.setText(getIntent().getStringExtra("title")+"-竞买记录");
        initViewPager();
    }

    private void initViewPager() {
        mFragments = new ArrayList<>();
        mFragments.add(AllOfferFragment.newInstance(getIntent().getStringExtra("no")));//全部出价
        mFragments.add(MyOfferFragment.newInstance(getIntent().getStringExtra("no"))); //材料采购
        mPagerAdapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, mTitles);
        mBinding.viewPager.setOffscreenPageLimit(mTitles.length);
        mBinding.viewPager.setAdapter(mPagerAdapter);
        mBinding.tabLayout.setupWithViewPager(mBinding.viewPager);
    }


}
